home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Color < prev    next >
Text File  |  1993-06-24  |  2KB  |  137 lines

  1. macro 'Color Merge Two Images';
  2. {
  3. Merges a "red" image and a "green" image to
  4. create a composite color image by creating a
  5. temporary 24-bit image and converted to 8-bits.
  6. }
  7. var
  8.   i,w1,w2,h1,h2,rgb:integer;
  9. begin
  10.   Requires(1.50);
  11.   SaveState;
  12.   if nPics<>2 then begin
  13.     PutMessage('This macro operates on exactly two images.');
  14.     exit;
  15.   end;
  16.   SelectPic(1);
  17.   GetPicSize(w1,h1);
  18.   SelectPic(2);
  19.   GetPicSize(w2,h2);
  20.   if (w1<>w2) or (h1<>h2) then begin
  21.     PutMessage('The two images must have the same width and height.');
  22.     exit;
  23.   end;
  24.   SetNewSize(w1,h2);
  25.   SetBackground(255);
  26.   MakeNewStack('RGB');
  27.   AddSlice;
  28.   AddSlice;
  29.   rgb:=PicNumber;
  30.   SelectPic(1);
  31.   SelectAll;
  32.   Copy;
  33.   SelectPic(rgb);
  34.   SelectSlice(1);
  35.   Paste;
  36.   Invert;
  37.   SelectPic(2);
  38.   SelectAll;
  39.   Copy;
  40.   SelectPic(rgb);
  41.   SelectSlice(2);
  42.   Paste;
  43.   Invert;
  44.   RGBToIndexed('Custom');
  45.   SelectPic(rgb);
  46.   Dispose;
  47.   RestoreState;
  48. end;
  49.  
  50.  
  51. macro 'Color Merge Two Stacks';
  52. {
  53. Merges a "red" stack and a "green" stack to
  54. create a new composite color stack.
  55. }
  56. var
  57.   i,w1,w2,h1,h2,d1,d2,d3:integer;
  58.   rgb,merged:integer;
  59. begin
  60.   Requires(1.50);
  61.   SaveState;
  62.   if nPics<>2 then begin
  63.     PutMessage('This macro operates on exactly two stacks.');
  64.     exit;
  65.   end;
  66.   SelectPic(1);
  67.   GetPicSize(w1,h1);
  68.   d1:=nSlices;
  69.   SelectPic(2);
  70.   GetPicSize(w2,h2);
  71.   d2:=nSlices;
  72.   if (d1=0) or (d2=0) then begin
  73.     PutMessage('Both images must be stacks.');
  74.     exit;
  75.   end;
  76.   if d1>=d2
  77.     then d3:=d2
  78.     else d3:=d1;
  79.   if (w1<>w2) or (h1<>h2) then begin
  80.     PutMessage('The two stacks must have the same width and height.');
  81.     exit;
  82.   end;
  83.   SetNewSize(w1,h2);
  84.   SetBackground(255);
  85.   MakeNewStack('RGB');
  86.   AddSlice;
  87.   AddSlice;
  88.   rgb:=PicNumber;
  89.   SetPalette('System');
  90.   MakeNewStack('Merged');
  91.   merged:=PicNumber;
  92.   for i:=1 to d3 do begin
  93.     SelectPic(1);
  94.     SelectSlice(i);
  95.     SelectAll;
  96.     Copy;
  97.     {DeleteSlice;}
  98.     SelectPic(rgb);
  99.     SelectSlice(1);
  100.     SelectAll;
  101.     Paste;
  102.     Invert;
  103.     SelectPic(2);
  104.     SelectSlice(i);
  105.     SelectAll;
  106.     Copy;
  107.     {DeleteSlice;}
  108.     SelectPic(rgb);
  109.     SelectSlice(2);
  110.     SelectAll;
  111.     Paste;
  112.     Invert;
  113.     SelectPic(rgb);
  114.     RGBToIndexed('System');
  115.     SelectAll;
  116.     Copy;
  117.     Dispose;
  118.     SelectPic(merged);
  119.     Paste;
  120.     if i<>d3 then AddSlice;
  121.    end;
  122.   SelectPic(rgb);
  123.   Dispose;
  124. {
  125.   SelectPic(1);
  126.   Dispose;
  127.   SelectPic(1);
  128.   Dispose;
  129. }
  130.   RestoreState;
  131. end;
  132.  
  133. macro 'RGB to Indexed';
  134. begin
  135.   RGBToIndexed('Custom LUT');
  136. end;
  137.